package com.zy.openchat.core.model.config;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.Gson;
import com.zy.openchat.App;

public class AppConfigInfo implements Parcelable {
    //true 仅好友可以聊天
    public boolean onlyFriendChat;
    //true 仅能添加白名单里的好友
    public boolean onlyWhiteAddFriend;
    public boolean permitModifyUserName = true;

    public boolean phone_code_login;
    public boolean register_need_phone_code;
    public boolean register_need_inviter;
    public int password_flood_interval;
    public boolean using_oss;
    //    1、发文件
    public boolean can_send_file;
    //2、位置
    public boolean  can_send_location;
    //3、红包
    public boolean can_send_redpacket;
    //4、转账
    public boolean can_remit;
    //5、联系人页面的通讯录
    public boolean can_see_address_book;
    //6、发现页面的朋友圈
    public boolean can_see_blog;
    //7、邀请好友
    public boolean can_invite_friend;
    //8、附近的人
    public boolean can_see_nearby;
    //9、公开的群
    public boolean can_see_public_group;
    //10、二维码
    public boolean can_see_qr_code;
    //11、我的钱包
    public boolean can_see_wallet;
    //12、交易记录
    public boolean can_see_wallet_records;
    //13、表情商店
    public boolean can_see_emoji_shop;
    //退群信息 非管理是否可见
    public  boolean shown_everyone_member_changes;
    //是否显示截屏提示
    public  boolean enabled_screenshot_notification;
    //是否屏蔽群在线人数
    public boolean  shown_online_members;
    //阅后即焚
    public  boolean enabled_destroy_after_reading;

//    phone_code_login bool 手机验证码登录
//    register_need_phone_code bool 注册需要手机验证码
//    register_need_inviter bool 注册需要邀请码

    //本地缓存
    public static AppConfigInfo getAppConfigInfo() {
        Context context = App.getInstanse();
        String jsonStr = context.getSharedPreferences("config", Context.MODE_PRIVATE).getString("app", null);
        if (jsonStr != null)
            return new Gson().fromJson(jsonStr, AppConfigInfo.class);
        return null;
    }

    public static void saveAppConfigInfo(AppConfigInfo info) {
        if (info == null) {
            return;
        }
        String jsonStr = new Gson().toJson(info);
        Context context = App.getInstanse();
        SharedPreferences.Editor editor = context.getSharedPreferences("config", Context.MODE_PRIVATE).edit();
        editor.putString("app", jsonStr);
        editor.apply();
    }

    public static AppConfigInfo getAppWithoutLoginConfigInfo() {
        Context context = App.getInstanse();
        String jsonStr = context.getSharedPreferences("config", Context.MODE_PRIVATE).getString("appConif", null);
        if (jsonStr != null)
            return new Gson().fromJson(jsonStr, AppConfigInfo.class);
        return null;
    }

    public static void saveAppWithoutLoginConfigInfo(AppConfigInfo info) {
        if (info == null) {
            return;
        }
        String jsonStr = new Gson().toJson(info);
        Context context = App.getInstanse();
        SharedPreferences.Editor editor = context.getSharedPreferences("config", Context.MODE_PRIVATE).edit();
        editor.putString("appConif", jsonStr);
        editor.apply();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte(this.onlyFriendChat ? (byte) 1 : (byte) 0);
        dest.writeByte(this.onlyWhiteAddFriend ? (byte) 1 : (byte) 0);
        dest.writeByte(this.permitModifyUserName ? (byte) 1 : (byte) 0);
        dest.writeByte(this.phone_code_login ? (byte) 1 : (byte) 0);
        dest.writeByte(this.register_need_phone_code ? (byte) 1 : (byte) 0);
        dest.writeByte(this.register_need_inviter ? (byte) 1 : (byte) 0);
        dest.writeInt(this.password_flood_interval);
        dest.writeByte(this.using_oss ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_send_file ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_send_location ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_send_redpacket ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_remit ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_see_address_book ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_see_blog ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_invite_friend ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_see_nearby ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_see_public_group ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_see_qr_code ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_see_wallet ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_see_wallet_records ? (byte) 1 : (byte) 0);
        dest.writeByte(this.can_see_emoji_shop ? (byte) 1 : (byte) 0);
        dest.writeByte(this.shown_everyone_member_changes ? (byte) 1 : (byte) 0);
        dest.writeByte(this.enabled_screenshot_notification ? (byte) 1 : (byte) 0);
        dest.writeByte(this.shown_online_members ? (byte) 1 : (byte) 0);
        dest.writeByte(this.enabled_destroy_after_reading ? (byte) 1 : (byte) 0);
    }

    public void readFromParcel(Parcel source) {
        this.onlyFriendChat = source.readByte() != 0;
        this.onlyWhiteAddFriend = source.readByte() != 0;
        this.permitModifyUserName = source.readByte() != 0;
        this.phone_code_login = source.readByte() != 0;
        this.register_need_phone_code = source.readByte() != 0;
        this.register_need_inviter = source.readByte() != 0;
        this.password_flood_interval = source.readInt();
        this.using_oss = source.readByte() != 0;
        this.can_send_file = source.readByte() != 0;
        this.can_send_location = source.readByte() != 0;
        this.can_send_redpacket = source.readByte() != 0;
        this.can_remit = source.readByte() != 0;
        this.can_see_address_book = source.readByte() != 0;
        this.can_see_blog = source.readByte() != 0;
        this.can_invite_friend = source.readByte() != 0;
        this.can_see_nearby = source.readByte() != 0;
        this.can_see_public_group = source.readByte() != 0;
        this.can_see_qr_code = source.readByte() != 0;
        this.can_see_wallet = source.readByte() != 0;
        this.can_see_wallet_records = source.readByte() != 0;
        this.can_see_emoji_shop = source.readByte() != 0;
        this.shown_everyone_member_changes = source.readByte() != 0;
        this.enabled_screenshot_notification = source.readByte() != 0;
        this.shown_online_members = source.readByte() != 0;
        this.enabled_destroy_after_reading = source.readByte() != 0;
    }

    public AppConfigInfo() {
    }

    protected AppConfigInfo(Parcel in) {
        this.onlyFriendChat = in.readByte() != 0;
        this.onlyWhiteAddFriend = in.readByte() != 0;
        this.permitModifyUserName = in.readByte() != 0;
        this.phone_code_login = in.readByte() != 0;
        this.register_need_phone_code = in.readByte() != 0;
        this.register_need_inviter = in.readByte() != 0;
        this.password_flood_interval = in.readInt();
        this.using_oss = in.readByte() != 0;
        this.can_send_file = in.readByte() != 0;
        this.can_send_location = in.readByte() != 0;
        this.can_send_redpacket = in.readByte() != 0;
        this.can_remit = in.readByte() != 0;
        this.can_see_address_book = in.readByte() != 0;
        this.can_see_blog = in.readByte() != 0;
        this.can_invite_friend = in.readByte() != 0;
        this.can_see_nearby = in.readByte() != 0;
        this.can_see_public_group = in.readByte() != 0;
        this.can_see_qr_code = in.readByte() != 0;
        this.can_see_wallet = in.readByte() != 0;
        this.can_see_wallet_records = in.readByte() != 0;
        this.can_see_emoji_shop = in.readByte() != 0;
        this.can_see_emoji_shop = in.readByte() != 0;
        this.can_see_emoji_shop = in.readByte() != 0;
        this.can_see_emoji_shop = in.readByte() != 0;
        this.can_see_emoji_shop = in.readByte() != 0;
    }

    public static final Creator<AppConfigInfo> CREATOR = new Creator<AppConfigInfo>() {
        @Override
        public AppConfigInfo createFromParcel(Parcel source) {
            return new AppConfigInfo(source);
        }

        @Override
        public AppConfigInfo[] newArray(int size) {
            return new AppConfigInfo[size];
        }
    };
}
